/**
 *
 */
package org.jenkon.commons.collection.utils;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import org.jenkon.commons.collection.factory.CollectionFactory;
import org.jenkon.commons.lang.utils.ArrayUtils;

/**
 * util class with helping methods for {@link Collection} handling.
 * 
 * @author Jens Konopka
 * 
 */
public final class CollectionUtils {

	/**
	 * hide public constructor for this util class.
	 */
	private CollectionUtils() {
	}

	/**
	 * check the {@link Collection} of is empty. if the {@link Collection} is <code>null</code> or the {@link Collection#isEmpty()} then return
	 * <code>true</code> and else return <code>false</code>.
	 * 
	 * @param values the {@link Collection} to check of is empty
	 * @return true oder false
	 */
	public static boolean isEmpty(final Collection<?> values) {
		return values == null ? true : values.isEmpty();
	}

	/**
	 * Wrap a array to a collection.
	 * 
	 * @param values the array with values to wrap
	 * @return the collection from array
	 */
	public static <T> Collection<T> toCollection(final T[] values) {
		final Collection<T> results = CollectionFactory.createCollection(List.class);
		if (ArrayUtils.isNotEmpty(values)) {
			results.addAll(Arrays.asList(values));
		}
		return results;
	}

}
